/*
 * SetDialog.cpp
 *
 *  Created on: 2011-7-21
 *      Author: fufan
 */
#include "setDialog.h"

SetDialog::SetDialog(MibItem *item, MibTree *parent, QStringList instances)
{
	setDialog = new Ui::Dialog();
	setDialog->setupUi(this);
	setDialog->buttonBox->button(QDialogButtonBox::Ok)->setText("确定");
	setDialog->buttonBox->button(QDialogButtonBox::Cancel)->setText("取消");

	QString name = item->dataValue(0).toString();
	QString oid = item->dataValue(1).toString();
	QString access = item->dataValue(2).toString();
	QString type = item->dataValue(5).toString();


	setDialog->name->setText(name);
	for(int i=0; i<instances.length(); i++)
	{
		setDialog->oid->addItem(instances[i]);
	}

	if(access=="read-only" || access == "not-accessible")
	{
		setDialog->value->setReadOnly(true);
	}
	setDialog->access->setText(access);
	setDialog->type->setText(type);
	setDialog->value->setFocus();

	connect(this, SIGNAL(accepted()), this, SLOT(sendSignal()));
	connect(this, SIGNAL(sendValue(const QString &, const QString &)), parent, SLOT(setValue(const QString &, const QString &)));

}

void SetDialog::sendSignal()
{
	if(setDialog->access->text()!="read-only" && setDialog->access->text() != "no-accessible")
	{
			emit sendValue(setDialog->oid->currentText(), setDialog->value->text());
	}
}
